(function(a) {
	a.extend( {
		progressBar : new function() {
			this.defaults = {
				steps : 20,
				stepDuration : 100,
				max : 100,
				showText : true,
				textFormat : "percentage",
				width : 120,
				height : 12,
				callback : null,
				boxImage : "./plugin/progressbar/images/progressbar.gif",
				barImage : {
					0 : "./plugin/progressbar/images/progressbg_red.gif",
					30 : "./plugin/progressbar/images/progressbg_orange.gif",
					50 : "./plugin/progressbar/images/progressbg_black.gif",
					70 : "./plugin/progressbar/images/progressbg_yellow.gif",
					90 : "./plugin/progressbar/images/progressbg_green.gif"
				},
				running_value : 0,
				value : 0,
				image : null
			};
			this.construct = function(c, b) {
				var d = null;
				var e = null;
				if (c != null) {
					if (!isNaN(c)) {
						d = c;
						if (b != null) {
							e = b
						}
					} else {
						e = c
					}
				}
				return this.each(function() {
					var o = this;
					var g = com.project.web.admin.config;
					if (d != null && this.bar != null && com.project.web.admin.config != null) {
						com.project.web.admin.config.value = parseInt(d);
						if (e != null) {
							o.config = a.extend(com.project.web.admin.config, e)
						}
						g = o.config
					} else {
						var m = a(this);
						var g = a.extend( {}, a.progressBar.defaults, e);
						g.id = m.attr("com.project.common.web.utils.id") ? m.attr("com.project.common.web.utils.id") : Math.ceil(Math
								.random() * 100000);
						if (d == null) {
							d = m.html().replace("%", "")
						}
						g.value = parseInt(d);
						g.running_value = 0;
						g.image = l(g);
						var p = [ "steps", "stepDuration", "max", "width",
								"height", "running_value", "value" ];
						for ( var h = 0; h < p.length; h++) {
							g[p[h]] = parseInt(g[p[h]])
						}
						if (g.value > g.max) {
							g.value = g.max
						}
						m.html("");
						var k = document.createElement("span");
						var r = document.createElement("span");
						var f = a(k);
						var n = a(r);
						o.bar = f;
						f.attr("com.project.common.web.utils.id", g.id + "_pbImage");
						n.attr("com.project.common.web.utils.id", g.id + "_pbText");
						n.html(q(g));
						f.attr("title", q(g));
						f.attr("width", g.width);
						f.css("width", g.width + "px");
						f.css("height", g.height + "px");
						f.attr("class","proImgBg");
						f.css("background-position", ((g.width * -1))
								+ "px 50%");
						f.css("padding", "0");
						f.css("margin", "0");
						m.append(f);
						m.append(n)
					}
					function j(i) {
						return Math.round(i.running_value * 100 / i.max)
					}
					function l(t) {
						var v = t.barImage;
						if (typeof (t.barImage) == "object") {
							for ( var u in t.barImage) {
								if (j(t) >= parseInt(u)) {
									v = t.barImage[u]
								} else {
									break
								}
							}
						}
						return v
					}
					function q(i) {
						if (i.showText) {
							if (i.textFormat == "percentage") {
								return " " + j(i) + "%"
							} else {
								if (i.textFormat == "fraction") {
									return " " + i.running_value + "/" + i.max
								}
							}
						}
					}
					g.increment = Math.round((g.value - g.running_value)
							/ g.steps);
					if (g.increment < 0) {
						g.increment *= -1
					}
					if (g.increment < 1) {
						g.increment = 1
					}
					
					var v = g.width / 100;
					g.running_value = g.value;
					var u = a("#" + g.id + "_pbImage");
					var i = a("#" + g.id + "_pbText");
					var t = l(g);
					if (t != g.image) {
						u.attr("class","proImgBg");
						g.image = t
					}
					u.css("background-position",
							(((g.width * -1)) + (j(g) * v)) + "px 50%");
					u.attr("title", q(g));
					i.html(q(g));
					
				})
			}
		}
	});
	a.fn.extend( {
		progressBar : a.progressBar.construct
	})
})(jQuery);